package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.common.enums.NoticeType;
import com.hxd.otc.module.my.adapter.AfficheAdapter;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.module.my.bean.NoticeBean;
import com.hxd.otc.module.my.contract.AfficheContract;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.net.BaseObserver;

/**
 * Created by lzy on 2018/6/15 0015.
 * description ${消息列表 Presenter}
 */
public class AffichePresenter extends BaseRecyclerPresenter<AfficheContract.View, AfficheAdapter, NoticeBean> implements AfficheContract.Presenter {

    private final UserModel mUserModel;
    private NoticeType mNoticeType;

    public AffichePresenter(AfficheContract.View view) {
        super(view);
        mUserModel = UserModel.getInstance();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mUserModel.getNoticeList(mPageIndex, getPageSize(), new BaseObserver<BaseListBean<NoticeBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull BaseListBean<NoticeBean> listBean) {
                onLoadDataSuccess(isRefresh, listBean.getList());
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<BaseListBean<NoticeBean>>>bindAutoDispose());
    }

    @Override
    public void lookNotice(final NoticeBean noticeBean) {
        mUserModel.lookList(noticeBean.getId(), new BaseObserver<String>() {

            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.lookNoticeSuccess(noticeBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.lookNoticeFail(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public int getPageSize() {
        return 15;
    }

    @Override
    public void setNotifyType(NoticeType noticeType) {
        mNoticeType = noticeType;
    }
}
